package com.fr.chart.core.glyph;

import com.fr.base.background.ColorBackground;
import com.fr.base.core.IteratorChain;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.marker.Marker;
import com.fr.chart.marker.TriangleFilledMarker;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.plot.MarkerGlyph;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class GanttPlotGlyph extends PlotGlyph
{
  private static final long serialVersionUID = 7888272466260745014L;
  public static final String XML_TAG = "GanttPlotGlyph";
  private CategoryAxisGlyph categoryAxisGlyph;
  private CategoryAxisGlyph dateAxisGlyph;

  public String getPlotGlyphType()
  {
    return "GanttPlotGlyph";
  }

  public void layoutAxisGlyph()
  {
    Rectangle2D localRectangle2D = getBounds();
    this.categoryAxisGlyph.dealPlotBoundsWithAxisLabel(localRectangle2D);
    this.dateAxisGlyph.dealPlotBoundsWithAxisLabel(localRectangle2D);
    this.categoryAxisGlyph.calculateAxisGlyph(localRectangle2D);
    this.dateAxisGlyph.calculateAxisGlyph(localRectangle2D);
    setBounds(localRectangle2D);
  }

  public void layoutDataSeriesGlyph()
  {
    double d1 = Math.min(this.categoryAxisGlyph.getUnitLen() / 3.0D, 20.0D);
    int i = 0;
    int j = getSeries(0).getDataPointCount();
    while (i < j)
    {
      int k = getSeriesSize();
      if (k > 1)
      {
        DataSeries localDataSeries1 = getSeries(0);
        DataPoint localDataPoint1 = localDataSeries1.getDataPoint(i);
        DataSeries localDataSeries2 = getSeries(1);
        DataPoint localDataPoint2 = localDataSeries2.getDataPoint(i);
        double d2 = localDataPoint1.getValue();
        double d3 = localDataPoint2.getValue();
        double d4 = this.dateAxisGlyph.getPoint2D(d2).getX();
        double d5 = this.dateAxisGlyph.getPoint2D(d3).getX();
        double d6 = this.categoryAxisGlyph.getPoint2DCateAxis(j - i - 1, 0.5D).getY();
        Rectangle2D.Double localDouble1 = new Rectangle2D.Double(d4, d6 - d1 / 2.0D, d5 - d4, d1);
        ShapeGlyph localShapeGlyph1 = new ShapeGlyph(localDouble1);
        localShapeGlyph1.setBackground(ColorBackground.getInstance(new Color(200, 199, 199)));
        localDataPoint1.setDrawImpl(localShapeGlyph1);
        if (k > 3)
        {
          DataSeries localDataSeries3 = getSeries(2);
          DataPoint localDataPoint3 = localDataSeries3.getDataPoint(i);
          DataSeries localDataSeries4 = getSeries(3);
          DataPoint localDataPoint4 = localDataSeries4.getDataPoint(i);
          double d7 = localDataPoint3.getValue();
          double d8 = localDataPoint4.getValue();
          double d9 = this.dateAxisGlyph.getPoint2D(d7).getX();
          double d10 = this.dateAxisGlyph.getPoint2D(d8).getX();
          double d11 = d6;
          TriangleFilledMarker localTriangleFilledMarker1 = new TriangleFilledMarker();
          localTriangleFilledMarker1.setSize(d1 / 4.0D);
          MarkerGlyph localMarkerGlyph1 = new MarkerGlyph(localTriangleFilledMarker1, new Color(113, 70, 22));
          localMarkerGlyph1.setShape(new Rectangle2D.Double(d9 - d1 / 4.0D, d11, d1 / 2.0D, d1 / 2.0D));
          localDataPoint3.setDrawImpl(localMarkerGlyph1);
          TriangleFilledMarker localTriangleFilledMarker2 = new TriangleFilledMarker();
          localTriangleFilledMarker2.setSize(d1 / 4.0D);
          MarkerGlyph localMarkerGlyph2 = new MarkerGlyph(localTriangleFilledMarker2, new Color(122, 190, 108));
          localMarkerGlyph2.setShape(new Rectangle2D.Double(d10 - d1 / 4.0D, d11, d1 / 2.0D, d1 / 2.0D));
          localDataPoint4.setDrawImpl(localMarkerGlyph2);
          if (k > 4)
          {
            DataSeries localDataSeries5 = getSeries(4);
            DataPoint localDataPoint5 = localDataSeries5.getDataPoint(i);
            double d12 = localDataPoint5.getValue();
            Rectangle2D.Double localDouble2 = new Rectangle2D.Double(d4, d6 - d1 / 2.0D, (d5 - d4) * d12, d1);
            ShapeGlyph localShapeGlyph2 = new ShapeGlyph(localDouble2);
            localShapeGlyph2.setBackground(ColorBackground.getInstance(new Color(0, 107, 172)));
            localDataPoint2.setDrawImpl(localShapeGlyph2);
          }
        }
      }
      ++i;
    }
  }

  public void draw(Graphics paramGraphics)
  {
    drawInfo(paramGraphics);
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    localGraphics2D.translate(getBounds().getX(), getBounds().getY());
    if (this.categoryAxisGlyph != null)
      this.categoryAxisGlyph.draw(paramGraphics);
    if (this.dateAxisGlyph != null)
      this.dateAxisGlyph.draw(localGraphics2D);
    localGraphics2D.translate(-getBounds().getX(), -getBounds().getY());
    super.draw(localGraphics2D);
  }

  public Iterator selectableChildren()
  {
    ArrayList localArrayList = new ArrayList();
    if (this.dateAxisGlyph != null)
      localArrayList.add(this.dateAxisGlyph);
    if (this.categoryAxisGlyph != null)
      localArrayList.add(this.categoryAxisGlyph);
    return new IteratorChain(new Iterator[] { localArrayList.iterator(), super.selectableChildren() });
  }

  public void setCategoryAxisGlyph(CategoryAxisGlyph paramCategoryAxisGlyph)
  {
    this.categoryAxisGlyph = paramCategoryAxisGlyph;
  }

  public CategoryAxisGlyph getCategoryAxisGlyph()
  {
    return this.categoryAxisGlyph;
  }

  public void setDateAxisGlyph(CategoryAxisGlyph paramCategoryAxisGlyph)
  {
    this.dateAxisGlyph = paramCategoryAxisGlyph;
  }

  public CategoryAxisGlyph getDateAxisGlyph()
  {
    return this.dateAxisGlyph;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("GanttPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    if (this.dateAxisGlyph != null)
      this.dateAxisGlyph.writeXML(paramXMLPrintWriter);
    if (this.categoryAxisGlyph != null)
      this.categoryAxisGlyph.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("DateAxisGlyph"))
        this.dateAxisGlyph = ((DateAxisGlyph)paramXMLableReader.readXMLObject(new DateAxisGlyph()));
      if (str.equals("CategoryAxisGlyph"))
        this.categoryAxisGlyph = ((CategoryAxisGlyph)paramXMLableReader.readXMLObject(new CategoryAxisGlyph()));
    }
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    if (this.categoryAxisGlyph != null)
      localJSONObject.put("categoryAxisGlyph", this.categoryAxisGlyph.toJSONObject());
    if (this.dateAxisGlyph != null)
      localJSONObject.put("dateAxisGlyph", this.dateAxisGlyph.toJSONObject());
    return localJSONObject;
  }
}